﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;
using System.Runtime.InteropServices;

using SuperMapLib;

namespace SDB2DM
{
    class Utility
    {
        /*定数*/
        public const string FEATURE_SCHOOL = "学校";
        public const string FEATURE_HOSPITAL = "病院";
        private const string DATASOURCE_ALIAS = "TokyoDM5Edit";

        #region XML文書に書き込み用
        //ヘッダー用
        public const string HEADER_VERSION_VALUE = "1.0";
        public const string HEADER_ENCODING_TYPE = "UTF-8";
        //ROOT用
        public const string ROOT_TAG = "GI";
        public const string NAMESPACE_TAG = "xmlns";
        public const string NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
        public const string JPS_URI = "http://www.gsi.go.jp/GIS/jpgis/standardSchemas1.0_2007-03";
        public const string XSI_TAG = "xsi";
        public const string XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
        public const string XLINK_TAG = "xlink";
        public const string XLINK_URI = "http://www.w3.org/1999/xlink";
        public const string SCHEMA_LOCATION_TAG = "schemaLocation";
        public const string SCHEMA_LOCATION_URI = CM_SCHEMA_URI + @"\Demo.xsd";
        public const string VERSION_TAG = "version";
        public const string TIMESTAMP_TAG = "timeStamp";
        //共通
        public const string CM_DOMAIN_TAG = "demo";
        public const string CM_JPS_TAG = "jps";
        public const string CM_SCHEMA_URI = @"\schema";
        public const string CM_LEVEL_DATASET_TAG = "Dataset";
        public const string CM_LEVEL_OBJECT_TAG = "Object";
        public const string CM_ATTRIBUTE_ID_TAG = "id";
        public const string CM_ATTRIBUTE_IDREF_TAG = "idref";
        //座標参照系
        public const string CRDT_RS_COMMENT = "座標参照系";
        public const string CRDT_RS_TAG = "RS_CRS";
        public const string CRDT_ID_PREFIX = "crs";
        public const string CRDT_RS_NAME_TAG = "RS_ReferenceSystem.name";
        public const string CRDT_IDENTIFIER_TAG = "RS_Identifier";
        public const string CRDT_IDENTIFIER_CODE_TAG = CRDT_IDENTIFIER_TAG + ".code";
        public const string CRDT_SPATIAL_RS_VALUE = "JGD2000 / (B, L)";   //日本測地系2000(世界測地系)/緯度経度
        public const string CRDT_TIME_RS_VALUE = "JC / JST";               //和暦/日本標準時
        //空間スキーマ用
        public const string SPATIAL_COMMENT = "空間スキーマ";
        public const string SPATIAL_POINT_TAG = "GM_Point";
        public const string SPATIAL_ID_PREFIX_POINT = "Demo-pt";
        public const string SPATIAL_POINT_POSITION_TAG = SPATIAL_POINT_TAG + ".position";
        public const string SPATIAL_DIRECT_POSITION_TAG = "DirectPosition";
        public const string SPATIAL_COORDINATE_TAG = SPATIAL_DIRECT_POSITION_TAG + ".coordinate";
        public const string SPATIAL_DIMENSION_TAG = SPATIAL_DIRECT_POSITION_TAG + ".dimension";
        public const string SPATIAL_DIMENSION_VALUE = "2";
        //応用スキーマ用
        public const string APP_COMMENT = "応用スキーマ";
        public const string APP_SCHOOL_TAG = "School";
        public const string APP_HOSPITAL_TAG = "Hospital";
        public const string APP_VISIBILITY_TAG = "visibility";
        public const string APP_VISIBILITY_VALUE = "可視";
        public const string APP_POS_TAG = "pos";
        //空間参照定義
        public const string SPATIAL_REF_COMMENT = "空間参照定義";
        public const string SPATIAL_REF_DEF_TAG = "Dataset.rs";
        #endregion

        /*変数*/
        public soDataSource objSource = null;
        private AxSuperMapLib.AxSuperWorkspace superWksp = null;
        private string SDBPath = string.Empty;

        public Utility(AxSuperMapLib.AxSuperWorkspace superWksp, string SDBPath)
        {
            this.superWksp = superWksp;
            this.SDBPath = SDBPath;
        }

        public void InitializeSource()
        {
            if (superWksp.Datasources[DATASOURCE_ALIAS] != null)
            {
                superWksp.Datasources.Remove(DATASOURCE_ALIAS);
            }

            objSource = superWksp.OpenDataSource(
                SDBPath, DATASOURCE_ALIAS, seEngineType.sceSDBPlus, true);
            if (objSource == null)
            {
                MessageBox.Show("initialize datasource fail");
            }
            else
            {
                //
            }
        }

        public void ReleaseMemory()
        {
            Marshal.ReleaseComObject(objSource);
            objSource = null;

            MessageBox.Show("Release memory OK!");
        }

    }
}
